//
//  LeaderView.m
//  duoduo
//
//  Created by wanghao on 16/11/7.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "LeaderView.h"
#import "AppDelegate.h"

@implementation LeaderView

+ (instancetype)leaderScrollViewWithTabBar:(UITabBarController *)tabBar withArray:(NSArray *)array
{
    AppDelegate * dele = [UIApplication sharedApplication].delegate;
    LeaderView * scro = [[LeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    scro.contentSize = CGSizeMake(ScreenWidth*array.count, 0);
    //分页
    scro.pagingEnabled = YES;
    //隐藏滚动条
    scro.showsVerticalScrollIndicator = NO;
    scro.showsHorizontalScrollIndicator = NO;
    //关闭弹簧
    scro.bounces = NO;

    UIPageControl * PageControl;
    //添加图片
    NSArray * array1  = @[@"firstPage",@"secondPage",@"thirdPage"];
    for (NSInteger i=0; i<array.count; i++) {
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth*i, 0, ScreenWidth, ScreenHeight)];
        imageView.image = [UIImage imageNamed:array[i]];
        [scro addSubview:imageView];

        imageView.userInteractionEnabled = YES;

        if (i==0) {
            UIView * view = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth*i, 0, ScreenWidth, ScreenHeight)];
            view.backgroundColor = [UIColor blackColor];
            UIImageView * upImageView = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth*i+60, 200, ScreenWidth-120, 30)];
            upImageView.image = [UIImage imageNamed:array1[i]];
            [view addSubview:upImageView];
            [imageView addSubview:view];

            UIImageView * ido = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth*i+100, 260, ScreenWidth-200, 40)];
            ido.image = [UIImage imageNamed:@"ido"];

            [view addSubview:ido];

            UIImageView * right = [[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth*i+ScreenWidth-200, 340, 190, 40)];
            right.image = [UIImage imageNamed:@"info"];

            [view addSubview:right];

            view.alpha = 0.3;
        }else if(i==1) {
            UIView * view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
            view.backgroundColor = [UIColor blackColor];
            UIImageView * upImageView = [[UIImageView alloc]initWithFrame:CGRectMake(60, 200, ScreenWidth-120, 60)];
            upImageView.image = [UIImage imageNamed:array1[i]];
            [view addSubview:upImageView];
            [imageView addSubview:view];

            UIImageView * ido = [[UIImageView alloc]initWithFrame:CGRectMake(100, 290, ScreenWidth-200, 40)];
            ido.image = [UIImage imageNamed:@"ido"];

            [view addSubview:ido];
            
            view.alpha = 0.3;
        }else{
            UIView * view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
            view.backgroundColor = [UIColor blackColor];
            UIImageView * upImageView = [[UIImageView alloc]initWithFrame:CGRectMake(60, 100, ScreenWidth-120, 90)];
            upImageView.image = [UIImage imageNamed:array1[i]];
            [view addSubview:upImageView];
            [imageView addSubview:view];

            UIImageView * ido = [[UIImageView alloc]initWithFrame:CGRectMake(100, 210, ScreenWidth-200, 40)];
            ido.image = [UIImage imageNamed:@"ido"];

            [view addSubview:ido];

            view.alpha = 0.3;
        }


        if (i==array.count-1) {
            UIButton * button = [[UIButton alloc]init];
            button.frame = CGRectMake(ScreenWidth-100, 30, 90, 40);
            [button setTitle:@"点击跳过" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:16];
            button.backgroundColor = [UIColor whiteColor];
            button.layer.cornerRadius = 8;
            button.layer.masksToBounds = YES;
            button.alpha = 0.5;
            [button addTarget:dele action:@selector(clickToSprite:) forControlEvents:UIControlEventTouchUpInside];
            [imageView addSubview:button];
        }
        //[scro bringSubviewToFront:button];

    }

    PageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(240, 230, 10, 10)];
    PageControl.numberOfPages = array.count;
    PageControl.currentPage = 0;
    [scro addSubview:PageControl];

    return scro;
}

@end
